package indi.madoka.weeb.module.base.service;

import indi.madoka.weeb.annotations.HandlerMethodMapping;
import indi.madoka.weeb.annotations.Keyword;
import indi.madoka.weeb.bean.update.message.MessageMatchingInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @author Arcueid
 */
@Service
@Slf4j
public class BaseService {

    public String listAllCommands() {
        Map<MessageMatchingInfo, Method> keywordMatchMethodMap = HandlerMethodMapping.KEYWORD_MATCH_METHOD_MAP;
        List<Keyword> keywordList = keywordMatchMethodMap.keySet()
                .stream()
                .map(MessageMatchingInfo::getAnnotation)
                .sorted(Comparator.comparing(Keyword::value))
                .collect(Collectors.toList());

        StringBuilder sb = new StringBuilder();
        sb.append("持续开发中\n");
        sb.append("项目仓库地址:https://gitee.com/meltllis/weebot\n");
        sb.append("=====命令列表=====\n");

        for (Keyword keyword : keywordList) {
            sb.append(keyword.value());
            sb.append(keyword.param());
            sb.append("---");
            sb.append(keyword.description());
            sb.append("\n");
        }
        log.info("list all commands---" + sb);
        return sb.toString();
    }
}
